# -*- coding: utf-8 -*-
"""
Testing Environment Settings

Configuration for testing environment with mocked services and fast execution.
"""

from typing import List
from pydantic import Field
from .base import BaseSettings


class TestingSettings(BaseSettings):
    """
    Testing environment configuration
    
    Optimized for unit and integration tests with minimal external dependencies.
    """
    
    environment: str = Field(default="testing", description="Environment name")
    
    # Debug Configuration
    debug: bool = Field(default=True, description="Enable debug mode for tests")
    reload: bool = Field(default=False, description="Disable auto-reload in tests")
    
    # API Configuration
    api_host: str = Field(default="127.0.0.1", description="API host")
    api_port: int = Field(default=8005, description="API port (different from dev)")
    
    # CORS - Permissive for testing
    cors_origins: List[str] = Field(
        default=["*"],
        description="Allow all origins in tests"
    )
    
    # Logging - Minimal for tests
    log_level: str = Field(default="WARNING", description="Logging level")
    log_file: str = Field(
        default="logs/tests.log",
        description="Test log file path"
    )
    
    # Cache - Disabled or very short TTL for tests
    cache_l1_enabled: bool = Field(default=False, description="Disable L1 cache")
    cache_l2_enabled: bool = Field(default=False, description="Disable L2 cache")
    cache_l3_enabled: bool = Field(default=False, description="Disable L3 cache")
    cache_l1_ttl: int = Field(default=1, description="L1 cache TTL (1 sec)")
    cache_l2_ttl: int = Field(default=1, description="L2 cache TTL (1 sec)")
    cache_l3_ttl: int = Field(default=1, description="L3 cache TTL (1 sec)")
    
    # Database - In-memory or test instances
    influxdb_url: str = Field(
        default="http://localhost:8086",
        description="InfluxDB URL (test instance)"
    )
    influxdb_token: str = Field(
        default="test-token",
        description="InfluxDB token (testing)"
    )
    influxdb_org: str = Field(
        default="test_org",
        description="InfluxDB organization (testing)"
    )
    influxdb_bucket: str = Field(
        default="test_bucket",
        description="InfluxDB bucket (testing)"
    )
    
    redis_host: str = Field(default="localhost", description="Redis host")
    redis_port: int = Field(default=6379, description="Redis port")
    redis_password: str = Field(default="", description="Redis password")
    redis_db: int = Field(default=15, description="Redis database (test DB)")
    
    # Resilience - Very lenient for tests
    resilience_circuit_breaker_enabled: bool = Field(
        default=False,
        description="Disable circuit breaker in tests"
    )
    resilience_rate_limiter_enabled: bool = Field(
        default=False,
        description="Disable rate limiter in tests"
    )
    resilience_retry_enabled: bool = Field(
        default=False,
        description="Disable retries in tests (for faster execution)"
    )
    resilience_default_timeout: float = Field(
        default=5.0,
        description="Shorter timeout for tests"
    )
    
    # Monitoring - Disabled for tests
    monitoring_enabled: bool = Field(
        default=False,
        description="Disable monitoring in tests"
    )
    
    # Performance - Minimal for tests
    worker_pool_size: int = Field(
        default=1,
        description="Single worker for tests"
    )
    max_concurrent_requests: int = Field(
        default=1,
        description="Sequential execution in tests"
    )
    
    # Batch size - Small for tests
    batch_size: int = Field(
        default=10,
        description="Small batch size for tests"
    )
    
    # Data retention - Minimal for tests
    data_retention_days: int = Field(
        default=1,
        description="1 day retention for tests"
    )
    
    # Real-time - Disabled for tests
    realtime_enabled: bool = Field(
        default=False,
        description="Disable real-time data in tests"
    )
    
    class Config:
        env_prefix = "TEST_"
        env_file = ".env.test"
        env_file_encoding = "utf-8"
        case_sensitive = False
        extra = "ignore"

